<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="zh-CN" />
<link href="../style/css/manual-zip.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
<link href="../style/css/manual-zip-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
<link href="../style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" />
<title>mod_mem_cache － Apache 2.2 中文手册 [金步国]</title>
<script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?d286c55b63a3c54a1e43d10d4c203e75"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script>
</head>
<body><div id="page-header">
<p class="menu"><a href="index.html">模块索引</a> | <a href="directives.html">指令索引</a> | <a href="../faq/index.html">常见问题</a> | <a href="../glossary.html">词汇表</a> | <a href="../sitemap.html">站点导航</a></p><p class="apache">Apache HTTP Server 版本2.2</p><img alt="" src="../images/feather.gif" /></div>
<div class="up"><a href="index.html"><img title="&lt;-" alt="&lt;-" src="../images/left.gif" /></a></div>
<div id="path"><a href="https://www.apache.org/">Apache</a> &gt; <a href="https://httpd.apache.org/">HTTP Server</a> &gt; <a href="https://httpd.apache.org/docs/">文档</a> &gt; <a href="../index.html">版本2.2</a> &gt; <a href="index.html">模块</a></div>

<div id="translation-info">　　 <a href="../translator_announcement.html#thanks">致谢</a> | 本篇译者：<a href="../../../index.html">金步国</a>(<a href="../../../index.html">作品集</a>) | 本页最后更新：2008年8月6日</div>
<div id="page-content"><div id="preamble"><h1>Apache模块 mod_mem_cache</h1>

<table border="1" cellpadding="0" cellspacing="0" bordercolor="#AAAAAA" class="module">
<tr><th><a href="module-dict.html#Description">说明</a></th><td>基于内存的缓冲管理器</td></tr>
<tr><th><a href="module-dict.html#Status">状态</a></th><td>扩展(E)</td></tr>
<tr><th><a href="module-dict.html#ModuleIdentifier">模块名</a></th><td>mem_cache_module</td></tr>
<tr><th><a href="module-dict.html#SourceFile">源文件</a></th><td>mod_mem_cache.c</td></tr>
</table>
<h3>概述</h3>

    <p>本模块需要<code class="module"><a href="mod_cache.html">mod_cache</a></code>提供的服务。它作为<code class="module"><a href="mod_cache.html">mod_cache</a></code>的辅助模块工作，以提供基于内存的存储管理。<code class="module"><a href="mod_mem_cache.html">mod_mem_cache</a></code>模块可以按两种方法来配置：①缓存打开的文件描述符；②在堆(heap)上缓存对象。<code class="module"><a href="mod_mem_cache.html">mod_mem_cache</a></code>既可以用于缓存本地生成的内容，也可以用于为<dfn>反向代理</dfn>模式下的<code class="module"><a href="mod_proxy.html">mod_proxy</a></code>(参见<code class="directive"><a href="mod_proxy.html#proxypass">ProxyPass</a></code>)缓存后端服务器输出的内容。</p>

    <p>内容将被以基于URI的索引存入和检出，但是并不保存相应的访问控制信息。</p>

	 <div class="note"><h3>注意:</h3>大多数情况下，<code class="module"><a href="mod_disk_cache.html">mod_disk_cache</a></code>都是首选。这在<a href="../caching.html#inmemory">缓冲指南</a>一文中有相应的解释。特别地，这个模块是<em>每进程(per-process)</em>类型的缓冲。</div>
</div>
<div class="top"><a href="mod_mem_cache.html#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="directive-section"><h2><a name="MCacheMaxObjectCount" id="MCacheMaxObjectCount">MCacheMaxObjectCount</a> <a name="mcachemaxobjectcount" id="mcachemaxobjectcount">指令</a></h2>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#AAAAAA" class="directive">
<tr><th><a href="directive-dict.html#Description">说明</a></th><td>最大缓存对象数</td></tr>
<tr><th><a href="directive-dict.html#Syntax">语法</a></th><td><code>MCacheMaxObjectCount <var>value</var></code></td></tr>
<tr><th><a href="directive-dict.html#Default">默认值</a></th><td><code>MCacheMaxObjectCount 1009</code></td></tr>
<tr><th><a href="directive-dict.html#Context">作用域</a></th><td>server config</td></tr>
<tr><th><a href="directive-dict.html#Status">状态</a></th><td>扩展(E)</td></tr>
<tr><th><a href="directive-dict.html#Module">模块</a></th><td>mod_mem_cache</td></tr>
</table>
    <p><code class="directive">MCacheMaxObjectCount</code>指令设定最大缓存对象数。这个值用来生成开放哈希表。如果一个新的对象要被插入缓存，而此时缓存的最大缓存对象数已达到极限，原来缓存的某个对象会被移走以允许新对象插入缓存。具体哪个对象被移走，是通过<code class="directive"><a href="mod_mem_cache.html#mcacheremovalalgorithm">MCacheRemovalAlgorithm</a></code>指令指定的算法来确定的。</p>

    <div class="example"><h3>示例</h3><p><code>
      MCacheMaxObjectCount 13001
    </code></p></div>

</div>
<div class="top"><a href="mod_mem_cache.html#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="directive-section"><h2><a name="MCacheMaxObjectSize" id="MCacheMaxObjectSize">MCacheMaxObjectSize</a> <a name="mcachemaxobjectsize" id="mcachemaxobjectsize">指令</a></h2>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#AAAAAA" class="directive">
<tr><th><a href="directive-dict.html#Description">说明</a></th><td>缓存允许的最大文档大小(字节)</td></tr>
<tr><th><a href="directive-dict.html#Syntax">语法</a></th><td><code>MCacheMaxObjectSize <var>bytes</var></code></td></tr>
<tr><th><a href="directive-dict.html#Default">默认值</a></th><td><code>MCacheMaxObjectSize 10000</code></td></tr>
<tr><th><a href="directive-dict.html#Context">作用域</a></th><td>server config</td></tr>
<tr><th><a href="directive-dict.html#Status">状态</a></th><td>扩展(E)</td></tr>
<tr><th><a href="directive-dict.html#Module">模块</a></th><td>mod_mem_cache</td></tr>
</table>
    <p><code class="directive">MCacheMaxObjectSize</code>指令设定允许缓存的最大文档大小(以Byte为单位)。</p>

    <div class="example"><h3>示例</h3><p><code>
      MCacheMaxObjectSize 6400000
    </code></p></div>

    <div class="note"><h3>注意</h3>
      <p><code class="directive">MCacheMaxObjectSize</code>的值必须大于<code class="directive"><a href="mod_mem_cache.html#mcacheminobjectsize">MCacheMinObjectSize</a></code>的值。</p>
    </div>

</div>
<div class="top"><a href="mod_mem_cache.html#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="directive-section"><h2><a name="MCacheMaxStreamingBuffer" id="MCacheMaxStreamingBuffer">MCacheMaxStreamingBuffer</a> <a name="mcachemaxstreamingbuffer" id="mcachemaxstreamingbuffer">指令</a></h2>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#AAAAAA" class="directive">
<tr><th><a href="directive-dict.html#Description">说明</a></th><td>内存中允许缓冲的最大流式响应字节长度</td></tr>
<tr><th><a href="directive-dict.html#Syntax">语法</a></th><td><code>MCacheMaxStreamingBuffer <var>size_in_bytes</var></code></td></tr>
<tr><th><a href="directive-dict.html#Default">默认值</a></th><td><code>MCacheMaxStreamingBuffer 100000与MCacheMaxObjectSize中的小者</code></td></tr>
<tr><th><a href="directive-dict.html#Context">作用域</a></th><td>server config</td></tr>
<tr><th><a href="directive-dict.html#Status">状态</a></th><td>扩展(E)</td></tr>
<tr><th><a href="directive-dict.html#Module">模块</a></th><td>mod_mem_cache</td></tr>
</table>
    <p><code class="directive">MCacheMaxStreamingBuffer</code>内存中允许缓冲的最大流式响应字节长度，以决定这个流式响应是否太长而不能被缓存。流式响应是指整个响应内容无法完整地得到，并且<code>Content-Length</code>也末知的响应。流式响应的来源包括代理的响应内容和CGI脚本的输出。默认情况下，除非响应头包含<code>Content-Length</code>信息，否则流式响应<em>不会</em>被缓存。这样做是为了避免使用大量内存缓存那些最终因为太长而不能缓存的响应。而<code class="directive">MCacheMaxStreamingBuffer</code>指令允许缓存不含<code>Content-Length</code>的流式响应，直到达到其指定的值。如果达到了最大流式响应可缓冲长度，已经被缓存的内容将会被释放，缓存也不再继续。</p>

    <div class="note"><h3>注意：</h3>
      <p>对<code class="directive">MCacheMaxStreamingBuffer</code>使用一个非零值不会对响应传送到客户产生延迟。当<code class="module"><a href="mod_mem_cache.html">mod_mem_cache</a></code>模块将流式化的内容复制到缓冲区的同时会将数据块传送到下一个输入点以传送给客户端。</p>
    </div>

    <div class="example"><p><code>
      # 指定最大流式响应可缓冲长度为 64KB<br />
      MCacheMaxStreamingBuffer 65536
    </code></p></div>

</div>
<div class="top"><a href="mod_mem_cache.html#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="directive-section"><h2><a name="MCacheMinObjectSize" id="MCacheMinObjectSize">MCacheMinObjectSize</a> <a name="mcacheminobjectsize" id="mcacheminobjectsize">指令</a></h2>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#AAAAAA" class="directive">
<tr><th><a href="directive-dict.html#Description">说明</a></th><td>允许缓存的最小文档大小(字节)</td></tr>
<tr><th><a href="directive-dict.html#Syntax">语法</a></th><td><code>MCacheMinObjectSize <var>bytes</var></code></td></tr>
<tr><th><a href="directive-dict.html#Default">默认值</a></th><td><code>MCacheMinObjectSize 0</code></td></tr>
<tr><th><a href="directive-dict.html#Context">作用域</a></th><td>server config</td></tr>
<tr><th><a href="directive-dict.html#Status">状态</a></th><td>扩展(E)</td></tr>
<tr><th><a href="directive-dict.html#Module">模块</a></th><td>mod_mem_cache</td></tr>
</table>
    <p><code class="directive">MCacheMinObjectSize</code>指令设定允许缓存的最小文档大小。</p>

    <div class="example"><h3>示例</h3><p><code>
      MCacheMinObjectSize 10000
    </code></p></div>

</div>
<div class="top"><a href="mod_mem_cache.html#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="directive-section"><h2><a name="MCacheRemovalAlgorithm" id="MCacheRemovalAlgorithm">MCacheRemovalAlgorithm</a> <a name="mcacheremovalalgorithm" id="mcacheremovalalgorithm">指令</a></h2>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#AAAAAA" class="directive">
<tr><th><a href="directive-dict.html#Description">说明</a></th><td>定义在需要时哪个文档被移出缓存的算法</td></tr>
<tr><th><a href="directive-dict.html#Syntax">语法</a></th><td><code>MCacheRemovalAlgorithm LRU|GDSF</code></td></tr>
<tr><th><a href="directive-dict.html#Default">默认值</a></th><td><code>MCacheRemovalAlgorithm GDSF</code></td></tr>
<tr><th><a href="directive-dict.html#Context">作用域</a></th><td>server config</td></tr>
<tr><th><a href="directive-dict.html#Status">状态</a></th><td>扩展(E)</td></tr>
<tr><th><a href="directive-dict.html#Module">模块</a></th><td>mod_mem_cache</td></tr>
</table>
    <p><code class="directive">MCacheRemovalAlgorithm</code>指令定义在需要时哪个文档被移出缓存。可以有两种选择：</p>

    <dl>
      <dt><code>LRU</code> (最近最少使用)</dt>
      <dd><code>LRU</code> 指定最长时间没有用到的对象将在必要的时候移出缓存。</dd>

      <dt><code>GDSF</code> (GreadyDual-Size)</dt>
      <dd><code>GDSF</code> 基于缓存命中率和文档大小计算优先级。在必要时，优先级最低的文档被移出缓存。</dd>
    </dl>

    <div class="example"><h3>示例</h3><p><code>
      MCacheRemovalAlgorithm GDSF<br />
      MCacheRemovalAlgorithm LRU
    </code></p></div>

</div>
<div class="top"><a href="mod_mem_cache.html#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="directive-section"><h2><a name="MCacheSize" id="MCacheSize">MCacheSize</a> <a name="mcachesize" id="mcachesize">指令</a></h2>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#AAAAAA" class="directive">
<tr><th><a href="directive-dict.html#Description">说明</a></th><td>缓存允许使用的最大内存量，以KB为单位</td></tr>
<tr><th><a href="directive-dict.html#Syntax">语法</a></th><td><code>MCacheSize <var>KBytes</var></code></td></tr>
<tr><th><a href="directive-dict.html#Default">默认值</a></th><td><code>MCacheSize 100</code></td></tr>
<tr><th><a href="directive-dict.html#Context">作用域</a></th><td>server config</td></tr>
<tr><th><a href="directive-dict.html#Status">状态</a></th><td>扩展(E)</td></tr>
<tr><th><a href="directive-dict.html#Module">模块</a></th><td>mod_mem_cache</td></tr>
</table>
    <p><code class="directive">MCacheSize</code>指令设定缓存允许使用的最大内存量，以KB(1024-byte)为单位。如果一个新的比缓存剩余内存量大的对象要插入缓存，那么原来缓存内的对象会被移走，直到这个新的对象能被插入缓冲区。具体哪个对象被移走，是通过<code class="directive"><a href="mod_mem_cache.html#mcacheremovalalgorithm">MCacheRemovalAlgorithm</a></code>指令指定的算法来确定的。</p>

    <div class="example"><h3>示例</h3><p><code>
      MCacheSize 700000
    </code></p></div>

    <div class="note"><h3>注意</h3>
      <p><code class="directive">MCacheSize</code>的值必须比<code class="directive"><a href="mod_mem_cache.html#mcachemaxobjectsize">MCacheMaxObjectSize</a></code>的值大。</p>
    </div>

</div>
</div>
<div id="footer">
<p class="apache">本文允许自由的转载、引用、再分发，但必须保留译者署名并注明出处；详见：<a href="../translator_announcement.html#announcement">版权声明</a>。</p>
<p class="menu"><a href="index.html">模块索引</a> | <a href="directives.html">指令索引</a> | <a href="../faq/index.html">常见问题</a> | <a href="../glossary.html">词汇表</a> | <a href="../sitemap.html">站点导航</a></p></div>
</body></html>
